home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Portable Patmos 1.1 / patmos-src / src / getargs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-19  |  3.6 KB  |  189 lines  |  [TEXT/KAHL]

  1. #include "crtlocal.h"
  2. #include <Dialogs.h>
  3. #include <OSUtils.h>
  4. #include <Resources.h>
  5.  
  6. #ifdef THINK_C
  7. #include <LoMem.h>
  8. #define can CurApName
  9. #else
  10. #include <SysEqu.h>
  11. #define can (char *)CurApName
  12. #endif
  13.  
  14. enum {
  15.     cmdLine = 3, labelLine, execute
  16. };
  17.  
  18. static struct {
  19.     short            count;
  20.     struct {
  21.         Handle            h;
  22.         Rect            box;
  23.         char            kind;
  24.     }                item[13];
  25. } itemList = { 5,
  26.  
  27.         /*  OK  */
  28.     0, { 76, 100, 96, 160 }, ctrlItem+btnCtrl,
  29.  
  30.         /*  Cancel  */
  31.     0, { 76, 210, 96, 270 }, ctrlItem+btnCtrl,
  32.     
  33.         /*  command line  */
  34.     0, { 41, 34, 57, 376 }, editText+itemDisable,
  35.         
  36.         /*  "Command Line:"  */
  37.     0, { 14, 20, 30, 170 }, statText+itemDisable,
  38.  
  39.         /*  Execute  */
  40.     0, { 76, 320, 96, 380 }, ctrlItem+btnCtrl,
  41.     
  42. };
  43.  
  44. /*
  45.  *  ditem - return item handle
  46.  *
  47.  */
  48.  
  49. static DialogPtr dp;
  50.  
  51. static Handle ditem(int);
  52.  
  53. static Handle ditem(int i)
  54. {
  55.     short kind;
  56.     Handle item;
  57.     Rect box;
  58.     
  59.     GetDItem(dp, i, &kind, &item, &box);
  60.     return(item);
  61. }
  62.  
  63. #if 0
  64.  
  65. enum { NARGS = 255};
  66.  
  67. static int argc;
  68. static Str255 argbuf;
  69. static char *argvec[NARGS+1];
  70.  
  71. static void parse(char *s, char *t)
  72.     {
  73.     int c = *s++, quote = 0;
  74.     argc = 0;
  75.     s[(unsigned char)c] = 0;
  76.     while (c = *s++) {
  77.         if (c == ' ')
  78.             continue;
  79.         if (argc < NARGS)
  80.             argvec[argc++] = t;
  81.         do {
  82.             if (c == '\\' && *s)
  83.                 c = *s++;
  84.             else if (c == '"' || c == '\'') {
  85.                 if (!quote) {
  86.                     quote = c;
  87.                     continue;
  88.                 }
  89.                 if (c == quote) {
  90.                     quote = 0;
  91.                     continue;
  92.                 }
  93.             }
  94.             *t++ = c;
  95.         } while (*s && ((c = *s++) != ' ' || quote));
  96.         *t++ = 0;
  97.     }
  98.     argvec[argc] = 0;
  99. }
  100.  
  101. #endif
  102.  
  103. #ifdef THINK_C
  104. /* avoid dragging in macTraps */
  105. #pragma parameter __A0 myPtrToHand(__A0,__D0)
  106. pascal Handle myPtrToHand(const void *srcPtr, long size) = 0xA9E3;
  107. #endif
  108.  
  109. #include <Aliases.h>
  110.  
  111. void BeginProcessing(void)
  112.     {
  113.     }
  114.  
  115. void EndProcessing(void)
  116.     {
  117.     }
  118.  
  119. #if 0
  120. void crt_getargs(void)
  121.    {
  122.     short i;
  123.     Rect bounds = { 60, 51, 170, 461 };
  124.     Handle items;
  125. #ifdef THINK_C
  126. /* avoid dragging in macTraps */
  127.     items = myPtrToHand(&itemList,sizeof(itemList));
  128. #else
  129.     i = PtrToHand(&itemList, &items, sizeof(itemList));
  130. #endif
  131.     dp = NewDialog(0, &bounds, (unsigned char *)"\006 line", 0, 1, (WindowPtr) -1, 0, 0, items);
  132.     SetCTitle((ControlHandle)ditem(ok), (unsigned char *)"\003OK");
  133.     SetCTitle((ControlHandle)ditem(cancel), (unsigned char *)"\006Cancel");
  134.     SetCTitle((ControlHandle)ditem(execute), (unsigned char *)"\007Execute");
  135.     SetIText(ditem(labelLine), (unsigned char *)"\015Command Line:");
  136.     SetIText(ditem(cmdLine), (unsigned char *)"\000" );
  137.     SelIText(dp, cmdLine, 9999, 9999);
  138.     ShowWindow(dp);
  139.     SetCursor(&qd.arrow);    
  140.     do {
  141.         ModalDialog(0, &i);
  142.         if (i == ok) GetIText(ditem(cmdLine), (void *)argbuf);
  143.         }
  144.     while ((i != ok) && (i != cancel) && (i != execute));
  145.     if (i == execute)
  146.         {
  147.         GetIText(ditem(cmdLine), (void *)argbuf);
  148.         DisposDialog(dp);
  149.         BeginProcessing();
  150.         EndProcessing();
  151.         }
  152.     else DisposDialog(dp);
  153.     }
  154. #endif
  155.  
  156. void scanfolder(FSSpec *curDocFSS)
  157.     {
  158.     CInfoPBRec curDocPB;
  159.     int i;
  160.     FSSpec    new;
  161.     OSErr err;
  162.     OSErr iErr;
  163.     curDocPB.hFileInfo.ioVRefNum = curDocFSS->vRefNum;
  164.     curDocPB.hFileInfo.ioDirID = curDocFSS->parID;
  165.     curDocPB.hFileInfo.ioNamePtr = curDocFSS->name;
  166.     curDocPB.hFileInfo.ioFDirIndex = 0;    
  167.     err = PBGetCatInfoSync (&curDocPB);
  168.     new.parID = curDocPB.hFileInfo.ioDirID;
  169.     new.vRefNum = curDocFSS->vRefNum;
  170.     for (i = 1; err != fnfErr; i++) 
  171.         {
  172.         curDocPB.hFileInfo.ioVRefNum = new.vRefNum;
  173.         curDocPB.hFileInfo.ioDirID = new.parID;
  174.         curDocPB.hFileInfo.ioNamePtr = new.name;
  175.         curDocPB.hFileInfo.ioFDirIndex = i;    
  176.         err = PBGetCatInfoSync (&curDocPB);
  177.         if (err == noErr)
  178.             {
  179.             Boolean isFolder,wasAlias;
  180.             err = ResolveAliasFile (&new, true, &isFolder, &wasAlias);
  181.             if (err == noErr) 
  182.                 {
  183.                 if (isFolder) scanfolder(&new);
  184.                 else ProcessDoc (&new);
  185.                 }
  186.             }
  187.         }
  188.     }
  189.